# -*- coding: utf-8 -*-
from bs4 import BeautifulSoup
from pathlib import Path
import requests

# 直接获取当前文件的父目录
current_dir = Path(__file__).parent
# resolve()解析符号链接
current_path=current_dir.resolve()
# 自动适配系统分隔符
combined_path = current_path / "PinDuoDuoHtml.txt"
# 一次性读取整个文件
with open(combined_path, 'r', encoding='utf-8') as f:
    html_string = f.read()

# 使用lxml解析器
soup = BeautifulSoup(html_string, 'lxml')
 
# 正确属性查找方式
content = soup.find(role='dialog')

if not content:
    print("未找到role='dialog'的元素")
    exit()
 
# 获取直接子div元素
direct_divs = [child for child in content.children if child.name == 'div']
second_div = direct_divs[1]
first_child_of_second_div = second_div.contents[0]
#print(first_child_of_second_div)python 
bIhLWVqm=first_child_of_second_div.contents[1]

 # 获取直接子span  
direct_div = [aria for aria in bIhLWVqm.children if aria.name == 'div']  
      
for i, aria in enumerate(direct_div):  
    direct_span = [direct_span for direct_span in aria.children if direct_span.name == 'span']  
    span_text=direct_span[0].text.strip()
    #print(span_text)
    # 替换中文括号为英文括号  
    text = span_text.replace('（', '(').replace('）', ')') 
    spaceText = text.replace('【', '(').replace('】', ')')  
    cleaned = spaceText.strip()
    print(cleaned)
  
# 获取尺码
second_second_div = second_div.contents[1]
chi_ma_div=second_second_div.contents[1]
direct_div = [aria for aria in chi_ma_div.children if aria.name == 'div']  
for i, aria in enumerate(direct_div):  
    direct_span = [direct_span for direct_span in aria.children if direct_span.name == 'span']  
    span_text=direct_span[0].text.strip()
    # 替换中文括号为英文括号  
    text = span_text.replace('（', '(').replace('）', ')') 
    spaceText = text.replace('【', '(').replace('】', ')')  
    cleaned = spaceText.strip()
    print(cleaned)